package threadDemo1.construction;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-01
 * Time: 21:47
 */
class MyRunnable implements Runnable{

    @Override
    public void run() {
        System.out.println("这是MyRunnable2");
    }
}
class MyThread extends Thread{
    public MyThread(){
        super();
        //创建线程
    }
    public MyThread(Runnable runnable){
        super(runnable);
        runnable.run();
        //创建线程实现Runnable接口
    }
    public MyThread(String name){
        super(name);
        //创建线程同时给线程命名
    }
    public MyThread(Runnable runnable, String name){
        super(runnable,name);
        //创建线程实现Runnable接口同时给线程命名
    }
    @Override
    public void run() {}
}
public class ThreadDemo {
    public static void main(String[] args) {
        Runnable runnable = new MyRunnable();
        Thread thread1 = new MyThread();
        thread1.start();
        Thread thread2 = new MyThread(runnable);
        thread2.start();
        Thread thread3 = new MyThread("这是thread3线程");
        thread3.start();
        Thread thread4 = new MyThread(runnable,"这是thread4线程");
        thread4.start();
        System.out.println("thread main");
    }
}
